package actionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import util.DomainUtils;

public class AddToContactGroupValidationForm extends ActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String[] contacts_to_add = null;
	private String selected_contactgroup = null;

	public String[] getContacts_to_add() {
		return contacts_to_add;
	}

	public void setContacts_to_add(String[] contacts_to_add) {
		this.contacts_to_add = contacts_to_add;
	}

	public String getSelected_contactgroup() {
		return selected_contactgroup;
	}

	public void setSelected_contactgroup(String selected_contactgroup) {
		this.selected_contactgroup = selected_contactgroup;
	}

	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.contacts_to_add = null;
		this.selected_contactgroup = null;
	}

	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();

		HttpSession session = request.getSession(false);

		// Checking session
		if (session == null
				|| session.getAttribute(DomainUtils.CURRENT_USER_STRING) == null) {
			errors.add(DomainUtils.ALERT_ERROR_STRING, new ActionMessage(
					"session.error"));
			
			DomainUtils.keepParametersContent(request);
			
			return errors;
		}

		// nothing to check
		return errors;
	}

}
